package sixkey.controller;

/**
 * ClassName:FileUploadController
 * Package:sixkey.controller
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/6/5 - 23:57
 * @Version:v1.0
 */

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sixkey.annotation.LogAnnotation;
import sixkey.service.FileUploadService;
import sixkey.utils.ResResult;

import java.io.File;

/**
 * 阿里云OSS图片上传
 */
@Api("阿里云OSS图片上传")
@RestController
@RequiredArgsConstructor
public class FileUploadController {
    private final FileUploadService fileUploadService;

    @ApiOperation(value = "图片上传", httpMethod = "POST",response = ResResult.class, notes = "图片上传")
    @PostMapping("/upload")
    @LogAnnotation(model = "文件",operation = "文件上传")
    public ResResult uploadFile(MultipartFile file){
        String url = fileUploadService.uploadFileAvatar(file);
        return ResResult.okResult(url);
    }

    @ApiOperation(value = "删除图片", httpMethod = "POST",response = ResResult.class, notes = "删除图片")
    @PostMapping("/delete")
    public ResResult deleteFile(@RequestParam("filePath") String filePath){
        fileUploadService.deleteFile(filePath);
        return ResResult.okResult();
    }
}
